package wyx240412;

import java.util.LinkedList;

public class Solitaire {
    LinkedList<String> list = new LinkedList<>();

    public synchronized LinkedList<String> getList() {
        return list;
    }
    public synchronized String play(String s) {
        if (s.length() != 4)
            return "请输入四字成语！";
        else {
            String flag;
            try {
                String idiom = list.getLast();
                if (idiom.charAt(idiom.length() - 1) == s.charAt(0)) {
                    list.add(s);
                    flag = "接龙成功，再接再厉！";
                }else
                    flag = "接龙失败，再想一个！";
            } catch (Exception e) {
                list.add(s);
                flag="第一个成语！";
            }
            return flag;
        }
    }
}
